" {{ For pathogen.vim: auto load all plugins in .vim/bundle
execute pathogen#infect()
" }}
"use mouse
set mouse=a
" support truecolor
set termguicolors
" usd gruvbox theme
colorscheme gruvbox-material
" background dark
let g:gruvbox_material_background = 'medium'
let g:gruvbox_material_enable_bold = 1
let g:gruvbox_material_disable_italic_comment = 1
let g:gruvbox_material_enable_italic = 0
let g:gruvbox_material_enable_bold = 1
"let g:gruvbox_material_foreground= 'mix'
set bg=light
" set colorscheme bg
"let g:gruvbox_contrast_light='soft'
"let g:gruvbox_contrast_dark='hard'
" show current line
set cursorline
" highlight search result
set hlsearch
" not compatible with the old-fashion vi mode
set nocompatible
" allow backspacing over everything in insert mode
set bs=2
" command line history
set history=1024
" show the cursor position all the time
set ruler
" auto read when file is changed from outside
set autoread
" show line numbers
set number
" ignore case when searching
set ignorecase
" ignore these files while expanding wild chars
set wildignore=*.o,*.class,*.pyc,*.elc,*.a,*.lib
" auto indentation
set autoindent
" copy the previous indentation
set copyindent
" incremental search
set incsearch
" no *~ backup files
set nobackup
" ignore case if search pattern is all lowercase,case-sensitive otherwise
set smartcase
" insert tabs on the start of a line according to context
"set smarttab
" tab convert to space
set expandtab
" 4 space
set tabstop=4
" backspace
set softtabstop=4
" indent level
set shiftwidth=4
" default updatetime 4000ms is not good for async update
set updatetime=100

filetype plugin indent on

" yank to the system register (*) by default
set clipboard=unnamedplus
" Cursor shows matching ) and }
set showmatch
" Show current mode
set showmode
" start wild expansion in the command line using <TAB>
set wildchar=<TAB>
" wild char completion menu
set wildmenu

" set leader to comma key
let mapleader = ","

" {{ ENCODING SETTINGS
set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,big5,gb2312,latin1
" }}

" {{ vim-easymotion
let g:EasyMotion_do_mapping = 0 " Disable default mappings
" Bi-directional find motion
" Jump to anywhere you want with minimal keystrokes, with just one key binding.
" `s{char}{label}`
nmap ;; <Plug>(easymotion-s2)
" Use uppercase target labels and type as a lower case
let g:EasyMotion_use_upper = 1
" type `l` and match `l`&`L`
let g:EasyMotion_smartcase = 1
" Smartsign (type `3` and match `3`&`#`)
let g:EasyMotion_use_smartsign_us = 1
" }}

" {{ indenline
" set leading space
let g:indentLine_leadingSpaceChar = '·'
" set indentline char
"let g:indentLine_char = '¦'
" }}

" remove trailing spaces
nmap <leader>tr :%s/ \+$//g<CR>

" exit
nmap q :q!<CR>

" NredTree
 nmap \ :NERDTreeToggle<CR>

 "
 nmap 0 ^

" leader hotkeys
nmap <leader>w :write<CR>
nmap <leader>s2 :sp<CR>
nmap <leader>s3 :vs<CR>
nmap <leader>s1 <C-W>o
nmap <leader>s0 :close<CR>
nmap <leader>x2 :sp<CR>
nmap <leader>x3 :vs<CR>
nmap <leader>x1 <C-W>o
nmap <leader>x0 :close<CR>

syntax on " syntax highlight

let g:airline#extensions#tabline#enabled = 1

" gutentags 搜索工程目录的标志，碰到这些文件/目录名就停止向上一级目录递归
let g:gutentags_project_root = ['.root', '.svn', '.git', '.repo', '.project']

" 所生成的数据文件的名称
let g:gutentags_ctags_tagfile = '.tags'
" 同时开启 ctags 和 gtags 支持：
let g:gutentags_modules = []
if executable('ctags')
	let g:gutentags_modules += ['ctags']
endif
if executable('gtags-cscope') && executable('gtags')
	let g:gutentags_modules += ['gtags_cscope']
endif
" 将自动生成的 tags 文件全部放入 ~/.cache/tags 目录中，避免污染工程目录
let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags

" 配置 ctags 的参数
let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extras=+q']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']

" 检测 ~/.cache/tags 不存在就新建
if !isdirectory(s:vim_tags)
   silent! call mkdir(s:vim_tags, 'p')
endif
" 禁用 gutentags 自动加载 gtags 数据库的行为
let g:gutentags_auto_add_gtags_cscope = 0
let g:gutentags_trace = 0

" 使用 universal-ctags 的话需要下面这行，请反注释
let g:gutentags_ctags_extra_args += ['--output-format=e-ctags']

" 如何识别项目目录，从当前文件目录向父目录递归知道碰到下面的文件/目录
let g:Lf_RootMarkers = ['.project', '.root', '.repo', '.git']
let g:Lf_CacheDirectory = expand('~/.vim/cache')

" Leaderf all config
let g:Lf_WindowPosition = 'popup'
let g:Lf_PreviewInPopup = 1
let g:Lf_ShortcutF = "<leader>ff"

" should use `Leaderf gtags --update` first
let g:Lf_GtagsAutoGenerate = 0
let g:Lf_Gtagslabel = 'native-pygments'

" leaderf keybindings
noremap <leader>fb :<C-U><C-R>=printf("Leaderf buffer %s", "")<CR><CR>
noremap <leader>fm :<C-U><C-R>=printf("Leaderf mru %s", "")<CR><CR>
noremap <leader>ft :<C-U><C-R>=printf("Leaderf bufTag %s", "")<CR><CR>
noremap <leader>fl :<C-U><C-R>=printf("Leaderf line %s", "")<CR><CR>
noremap <leader>fr :<C-U><C-R>=printf("Leaderf! gtags -r %s --auto-jump", expand("<cword>"))<CR><CR>
noremap <leader>fd :<C-U><C-R>=printf("Leaderf! gtags -d %s --auto-jump", expand("<cword>"))<CR><CR>
noremap <leader>fo :<C-U><C-R>=printf("Leaderf! gtags --recall %s", "")<CR><CR>
noremap <leader>fn :<C-U><C-R>=printf("Leaderf gtags --next %s", "")<CR><CR>
noremap <leader>fp :<C-U><C-R>=printf("Leaderf gtags --previous %s", "")<CR><CR>
noremap <C-B> :<C-U><C-R>=printf("Leaderf! rg --current-buffer -e %s ", expand("<cword>"))<CR>
noremap <C-F> :<C-U><C-R>=printf("Leaderf! rg -e %s ", expand("<cword>"))<CR>
